/**
 * Created with JetBrains WebStorm.
 * User: Tagit
 * Date: 30/4/13
 * Time: 12:01 PM
 * To change this template use File | Settings | File Templates.
 */

describe("MailboxDetailsController",function(){
    var mailboxDetailsController = null;
    var t_alertCtrl = null;
    var t_loadingCtrl = null;

    beforeEach(function(){
        //need feature
        t_alertCtrl = App.AlertController.create();
        t_loadingCtrl = App.LoadingController.create();
        App.MailboxDetailsController.reopen({
            init:function(){
                this.set('controllers.alert', t_alertCtrl);
                this.set('controllers.loading', t_loadingCtrl);
            }
        });
        mailboxDetailsController = App.MailboxDetailsController.create();
    });

    it("prepareController if -- is Html",function() {
        var response = {
            mailDetailResponse:{
                mail:{
                    body:"<"
                }
            }
        }
        var mailDetailObj = Ember.Object.create(response.mailDetailResponse.mail);
        spyOn(App.RouteHistory, "previousRoute").andReturn('mailbox.list');
        spyOn(App.Router, "getParameter").andReturn(mailDetailObj);
        spyOn(mailboxDetailsController, 'set');
        
        mailboxDetailsController.prepareController();
        
        expect(mailboxDetailsController.set).toHaveBeenCalledWith("message", mailDetailObj);
        expect(mailboxDetailsController.set).toHaveBeenCalledWith("isHtml", false);
    });
    
    it("prepareController if -- is not Html",function() {
    	var response = {
            mailDetailResponse:{
                mail:{
                    body:""
                }
            }
        }
    	var mailDetailObj = Ember.Object.create(response.mailDetailResponse.mail);
    	spyOn(App.RouteHistory, "previousRoute").andReturn('mailbox.list');
        spyOn(App.Router, "getParameter").andReturn(mailDetailObj);
        spyOn(mailboxDetailsController, 'set');
        
        mailboxDetailsController.prepareController();
        
        expect(mailboxDetailsController.set).toHaveBeenCalledWith("message", mailDetailObj);
        expect(mailboxDetailsController.set).toHaveBeenCalledWith("isHtml", false);
    });

    it("prepareController else",function() {
    	spyOn(App.RouteHistory, "previousRoute").andReturn('mailbox.list1');
    	
        mailboxDetailsController.prepareController();
        
        expect(mailboxDetailsController.get('message')).toEqual(null);
        expect(mailboxDetailsController.get('isHtml')).toBeFalsy();
    });
});